<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>聊天</title>
</head>
<body>
    <ul>
        <li>聊天消息：</li>
    </ul>

    <input type="text" placeholder="消息" class="txt">

    <script src="./lib/vue.js"></script>

    <script>
    //根据选择器查找元素
    const $=selector=>document.querySelector(selector)

    $('.txt').addEventListener('keydown',e=>{
        if(e.keyCode===13){
            // 回车，发送消息
            const input = e.target.value
            const li = `<li>${input}</li>`

            $('ul').innerHTNL+=li
            e.target.value=''
        }
    })
    
    </script>
</body>
</html>